<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.SQLException" %>
<jsp:useBean id="user" class="com.user"></jsp:useBean>
<jsp:setProperty name="user" property="*"></jsp:setProperty><%--
  Created by IntelliJ IDEA.
  User: 给
  Date: 2020/10/21
  Time: 8:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    Class.forName("com.mysql.jdbc.Driver");

    String url ="jdbc:mysql://localhost:3306/book";
    Connection connection = DriverManager.getConnection(url,"root","root");
    String sql ="update user set username =?,password =?,gender =?,age =? where id =?";

    PreparedStatement ps =connection.prepareStatement(sql);

    ps.setString(1,user.getUsername());
    ps.setString(2,user.getPassword());
    ps.setInt(3,user.getGender());
    ps.setInt(4,user.getAge());
    ps.setInt(5,user.getId());


    int count =ps.executeUpdate();

    if (count >0){
        out.print("修改成功");
    }
    else{
        out.print("修改失败");
    }
    response.setHeader("refresh","3;url=home.jsp");
%>